package com.sky.controller.user;

import com.sky.pojo.Setmeal;
import com.sky.result.Result;
import com.sky.service.common.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmeal")
@RequestMapping("/user/setmeal")
public class SetmealController {

    private static final Logger log = LoggerFactory.getLogger(SetmealController.class);
    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类查询套餐
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    public Result<List<SetmealVO>> list(Integer categoryId) {
        List<SetmealVO> bycategoryId = setmealService.findSetmealBycategoryId(categoryId);

        return Result.success(bycategoryId);
    }

    //根据套餐id查询包含的菜品
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> findDishBySetmealId(@PathVariable Long id) {
        List<DishItemVO> dishBySetmealId = setmealService.findDishBySetmealId(id);
        log.info("查询的菜品为：{}",dishBySetmealId);
        return Result.success(dishBySetmealId);
    }

}
